package com.fhx.core

import android.app.Activity
import android.content.Context
import android.content.Intent
import androidx.fragment.app.Fragment
import java.util.*

inline fun <reified T : Activity> Context.goToActivity() {
    val intent = Intent(this, T::class.java)
    startActivity(intent)
}

inline fun <reified T : Activity> Context.goToActivity(extra: Intent.() -> Unit) {
    val intent = Intent(this, T::class.java)
    intent.apply(extra)
    startActivity(intent)
}

inline fun <reified T : Activity> Activity.goToActivityForResult(requestCode: Int) {
    val intent = Intent(this, T::class.java)
    startActivityForResult(intent, requestCode)
}

inline fun <reified T : Activity> Activity.goToActivityForResult(requestCode: Int, extra: Intent.() -> Unit) {
    val intent = Intent(this, T::class.java)
    intent.apply(extra)
    startActivityForResult(intent, requestCode)
}

inline fun <reified T : Activity> Fragment.goToActivity() {
    val intent = Intent(context, T::class.java)
    startActivity(intent)
}

inline fun <reified T : Activity> Fragment.goToActivity(extra: Intent.() -> Unit) {
    val intent = Intent(context, T::class.java)
    intent.apply(extra)
    startActivity(intent)
}

inline fun <reified T : Activity> Fragment.goToActivityForResult(requestCode: Int) {
    val intent = Intent(context, T::class.java)
    startActivityForResult(intent, requestCode)
}

inline fun <reified T : Activity> Fragment.goToActivityForResult(requestCode: Int, extra: Intent.() -> Unit) {
    val intent = Intent(context, T::class.java)
    intent.apply(extra)
    startActivityForResult(intent, requestCode)


}